require 'config/boot'
require 'config/environment'

cashe_size = ENV['cashe_size'].nil? ? 1000 : ENV['cashe_size']
task :assign do
  size = Corpus.count
  limit = cashe_size
  repeat_times = (size / limit) + 1
  repeat_times.times{|i|
    p "#{i}/#{repeat_times}"
    Corpus.find(:all,
      :select =>"id,data",
      :limit => limit,
      :offset => limit * i
    ).each{|sentence|
      conditions = sentence.data.split("\t").uniq
      sentence.segments << Segment.find(:all,
        :select => "id",
        :conditions =>["data IN (?)",conditions]
      )
    }
  }
end